

package com.thxrinfo.car.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.log.annotation.SysLog;
import com.thxrinfo.car.api.entity.CarOwner;
import com.thxrinfo.car.service.CarOwnerService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


/**
 * 实名车主表
 *
 * @author silencezheng
 * @date 2023-02-08 17:47:32
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/carowner" )
@Tag(name = "实名车主表管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class CarOwnerController {

    private final  CarOwnerService carOwnerService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param carOwner 实名车主表
     * @return
     */
    @Operation(summary = "分页查询", description = "分页查询")
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('car_carowner_get')" )
    public R getCarOwnerPage(Page page, CarOwner carOwner) {
        return R.ok(carOwnerService.page(page, Wrappers.query(carOwner).lambda().orderByDesc(CarOwner::getCreateTime)));
    }


    /**
     * 通过id查询实名车主表
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id查询", description = "通过id查询")
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('car_carowner_get')" )
    public R getById(@PathVariable("id" ) Long id) {
        return R.ok(carOwnerService.getById(id));
    }

    /**
     * 新增实名车主表
     * @param carOwner 实名车主表
     * @return R
     */
    @Operation(summary = "新增实名车主表", description = "新增实名车主表")
    @SysLog("新增实名车主表" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('car_carowner_add')" )
    public R save(@RequestBody CarOwner carOwner) {
        return R.ok(carOwnerService.save(carOwner));
    }

    /**
     * 修改实名车主表
     * @param carOwner 实名车主表
     * @return R
     */
    @Operation(summary = "修改实名车主表", description = "修改实名车主表")
    @SysLog("修改实名车主表" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('car_carowner_edit')" )
    public R updateById(@RequestBody CarOwner carOwner) {
        return R.ok(carOwnerService.updateById(carOwner));
    }

    /**
     * 通过id删除实名车主表
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id删除实名车主表", description = "通过id删除实名车主表")
    @SysLog("通过id删除实名车主表" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('car_carowner_del')" )
    public R removeById(@PathVariable Long id) {
        return R.ok(carOwnerService.removeById(id));
    }

}
